gdk: Subtract base size when checking aspect ratio
authorVlad Zahorodnii <vlad.zahorodnii@kde.org>
Sat, 18 Jan 2020 23:56:35 +0000 (01:56 +0200)
committerVlad Zahorodnii <vladzzag@gmail.com>
Sun, 19 Jan 2020 00:22:44 +0000 (02:22 +0200)
According to the ICCCM spec [1], one should subtract the base size from
the window size before checking that the aspect ratio falls in range.

This change fixes shrinking Firefox Picture-in-Picture windows when
running KDE Plasma (with KWin as the window manager).

[1] https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.3

gdk/gdksurface.c

index 8424576238bcbce2db3258b0d2650a210e2cf538..dbc709bea6bd087d89ce5d33f2defe0b0a5fa2bf 100644 (file)
@@ -1726,6 +1726,16 @@ gdk_surface_constrain_size (GdkGeometry    *geometry,
     {
       gint delta;
 
+      if (flags & GDK_HINT_BASE_SIZE)
+        {
+          width -= base_width;
+          height -= base_height;
+          min_width -= base_width;
+          min_height -= base_height;
+          max_width -= base_width;
+          max_height -= base_height;
+        }
+
       if (geometry->min_aspect * height > width)
         {
           delta = FLOOR (height - width / geometry->min_aspect, yinc);
@@ -1751,6 +1761,12 @@ gdk_surface_constrain_size (GdkGeometry    *geometry,
                 height += delta;
             }
         }
+
+      if (flags & GDK_HINT_BASE_SIZE)
+        {
+          width += base_width;
+          height += base_height;
+        }
     }
 
 #undef FLOOR